文档章节

硬件之路-串行LCD12864之MSP430简单实现

爱吃橙子的小石头
 爱吃橙子的小石头
发布于 2014/08/13 18:04
字数 749
阅读 92
收藏 0


串行LCD12864引脚接法:

实现代码(MSP430):

/*
 * 12864.c
 *  Created on: 2014-7-15
 *      Author: bazingagain
 */
#include <msp430.h>
#include "12864.h"

/**
 * 函数名:delay
 * 功能:延时函数,延时时间为100us * x
 * 参数:x
 * 返回值:无
 */
void delay(uint x)
{
	uint i,j;
	for(j=0;j<x;j++)
		for(i=0;i<10;i++);
}
/**
 * 函数名:sendByte
 * 功能:向LCD12864串行发送1BYET数据
 * 参数:command
 * 返回值:无
 */
void sendByte(uchar command)
{
	uchar i;
	for(i=0;i<8;i++)
	{
		if((command<<i) & 0x80)
		{
			P2OUT |= BIT1;  //sid=1;
		}
		else
		{
			P2OUT &= (~BIT1); //sid=0;
		}
		P2OUT &= (~BIT2);  //SCLK=0
		P2OUT |= BIT2;  //SCLK=1

	}
}
/**
 * 函数名:writeCom
 * 功能:向LCD1264写指令函数
 * 参数:command
 * 返回值:无
 */
void writeCom(unsigned char command)
{
//	P2OUT |= BIT0;  //CS =P20  CS=1
	sendByte(0xf8);  //传送指令
	sendByte(command & 0xf0);
	sendByte((command << 4) & 0xf0);
	delay(2);
}
/**
 * 函数名:writeData
 * 功能:向LCD1286写数据函数
 * 参数:data
 * 返回值:无
 */
void writeData(unsigned char data)
{
//	P2OUT |= BIT0;  //CS=1;
	sendByte(0xfa);
	sendByte(data & 0xf0);
	sendByte((data << 4) & 0xf0);
	delay(2);
}
/**
 * 函数名:lcd_init
 * 功能:初始化LCD12864函数
 * 参数:无
 * 返回值:无
 */
void lcd_init(void)
{
	P2DIR |= BIT1 + BIT2; //SID , SCLK
	/*delay(20000);
	writeCom(0x30);  //设置8位数据接口,基本指令模式
	delay(50);
	writeCom(0x0c);  //整体显示开,游标关,反白关
	delay(50);*/
	writeCom(0x30);  //设置8位数据接口,基本指令模式
	writeCom(0x20);  //清DDRAM
	writeCom(0x06);  //游标及显示右移一位
	writeCom(0x0c);  //整体显示开,游标关,反白关
	writeCom(0x01);  //写入空格清屏
	writeCom(0x80);  //设置首次显示位置

}
/**
 * 函数名:displayOn12864
 * 功能:LCD12864显示字符函数
 * 参数:*s, addr
 * 返回值:无
 */
void displayOn12864(char *s, unsigned char addr)
{
	writeCom(addr);
	while(*s>0)
	{
		writeData(*s);
		s++;
		delay(50);
	}
}

51 mcu 写法:

#include <reg51.h>

/*
 * 12864.c
 *  Created on: 2015-3-31
 *      Author: bazingagain
 */
#include "12864.h"

sbit RW = P1^0;
sbit EN = P1^1;
 
/**
 * 函数名:delay
 * 功能:延时函数,延时时间为100us * x
 * 参数:x
 * 返回值:无
 */
void delay(uint x)
{
    uint i,j;
    for(j=0;j<x;j++)
        for(i=0;i<10;i++);
}
/**
 * 函数名:sendByte
 * 功能:向LCD12864串行发送1BYET数据
 * 参数:command
 * 返回值:无
 */
void sendByte(uchar command)
{
    uchar i;
    for(i=0;i<8;i++)
    {
        if((command<<i) & 0x80)
        {
            RW = 1;  //sid=1;
        }
        else
        {
            RW = 0//sid=0;
        }
        EN = 0;  //SCLK=0
        EN = 1;  //SCLK=1
 
    }
}
/**
 * 函数名:writeCom
 * 功能:向LCD1264写指令函数
 * 参数:command
 * 返回值:无
 */
void writeCom(unsigned char command)
{
	RW = 1;
    sendByte(0xf8);  //传送指令
    sendByte(command & 0xf0);
    sendByte((command << 4) & 0xf0);
    delay(2);
}
/**
 * 函数名:writeData
 * 功能:向LCD1286写数据函数
 * 参数:data
 * 返回值:无
 */
void writeData(unsigned char ddata)
{
    RW = 1;
    sendByte(0xfa);
    sendByte(ddata & 0xf0);
    sendByte((ddata << 4) & 0xf0);
    delay(2);
}
/**
 * 函数名:lcd_init
 * 功能:初始化LCD12864函数
 * 参数:无
 * 返回值:无
 */
void lcd_init(void)
{
    
    /*delay(20000);
    writeCom(0x30);  //设置8位数据接口,基本指令模式
    delay(50);
    writeCom(0x0c);  //整体显示开,游标关,反白关
    delay(50);*/
    writeCom(0x30);  //设置8位数据接口,基本指令模式
    writeCom(0x20);  //清DDRAM
    writeCom(0x06);  //游标及显示右移一位
    writeCom(0x0c);  //整体显示开,游标关,反白关
    writeCom(0x01);  //写入空格清屏
    writeCom(0x80);  //设置首次显示位置
 
}
/**
 * 函数名:displayOn12864
 * 功能:LCD12864显示字符函数
 * 参数:*s, addr
 * 返回值:无
 */
void displayOn12864(char *s, unsigned char addr)
{
    writeCom(addr);
    while(*s>0)
    {
        writeData(*s);
        s++;
        delay(50);
    }
}


© 著作权归作者所有

爱吃橙子的小石头
粉丝 0
博文 35
码字总数 12623
作品 0
沙坪坝
程序员
私信 提问
WuSiYu/BadApplePi

树莓派+Lcd12864播放Badapple 本项目实现在LCD12864显示屏(st7920控制器)上播放黑白动漫影绘视频:Badapple 在树莓派B+和2B上均能达到30fps(原视频帧数) 适用硬件 树莓派(Raspberry Pi):支...

WuSiYu
2015/08/26
0
0
利用Python做毕业设计,基于python的智能化门禁系统,远程控制!

社会发展的很快,人们的生活水平大幅度提高的同时,安全问题也愈受关注。 进小区要刷卡,公司刷卡,进学校宿舍刷卡,各种各样的刷卡安全系统在我们的生活里出现。简称为:门禁系统或出去管理...

柯西带你学编程
2018/06/07
0
0
LCD12864 cubie驱动显示

操作系统: 使用的是官方网站上的ubuntu sd card 1.1 1. 安装python的库和cubie的gpio库 sudo apt-get install python-dev wget http://dl.linux-sunxi.org/users/tom/pySUNXI-0.1.12.tar.gz......

cubieboard
2014/08/15
0
0
MSP430FG439上实现IO模拟UART以及移植要点解析

本文来自http://blog.csdn.net/hellogv/ ,引用必须注明出处! 最近要做MSP430上的开发,一上手就要做IO模拟UART这种难度的玩意,幸好网上已经有很多现成的MSP430的软串口实现例子,本文代码...

晨曦之光
2012/03/14
241
0
SPI (Serial Peripheral Interface)串行外设接口 协议详解+实例

SPI (Serial Peripheral Interface)串行外设接口 协议详解+实例 一、协议简介 SPI协议简介(转) (2008-04-26 16:24) 分类:单片机及硬件相关技术 来自:http://blog.chinaunix.net/space...

FreeBlues
2012/07/16
0
1

没有更多内容

加载失败,请刷新页面

加载更多
SpringCloudSleuth 链路跟踪

SpringCloudSleuth使用的核心组件是Twitter推出的Zipkin监控组件,zipkin就是一个分布式的跟踪系统,用户收集服务的数据 collector 收集器 rabbitmq ... storage 存储器 mysql ... 默认内存 ...

少年已不再年少
今天
3
0
Oracle PL/SQL

PL/SQL -- 输出功能 -- set serveroutput on size 10000 DECLARE -- 标量型变量 v_result NUMBER(8, 2); -- %TYPE会根据表中字段的类型定义变量 v_originName origin.originName%TYPE; v_con......

LoSingSang
今天
3
0
Node.js与RPC 的实践方案-Eggjs使用sofa-rpc-node模块

一、前言 SOFARPC 是蚂蚁金服开源的一个高可扩展性、高性能、生产级的 Java RPC 框架,提供了丰富的模型抽象和可扩展接口,包括过滤器、路由、负载均衡等等,致力于简化应用之间的 RPC 调用,...

AI考拉
今天
3
0
Qt开发经验总结之武林秘籍

一、开发经验总结 当编译发现大量错误的时候,从第一个看起,一个一个的解决,不要急着去看下一个错误,往往后面的错误都是由于前面的错误引起的,第一个解决后很可能都解决了。 定时器是个好...

飞扬青云
今天
3
0
聊聊Elasticsearch的EsThreadPoolExecutor

序 本文主要研究一下Elasticsearch的EsThreadPoolExecutor EsThreadPoolExecutor elasticsearch-7.0.1/server/src/main/java/org/elasticsearch/common/util/concurrent/EsThreadPoolExecuto......

go4it
今天
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部